package com.urls;

import java.net.MalformedURLException;
import java.net.URL;

public class UrlDemo01 {
    public static void main(String[] args) {
        String path = "http://localhost:8080/helloworld/index.jsp?username=ymb&pwd=123";
        try {
            URL url = new URL(path);
            // 获取协议
            System.out.println(url.getProtocol());// http
            // 主机IP
            System.out.println(url.getHost()); //  localhost
            // 端口
            System.out.println(url.getPort()); // 8080
            // 文件
            System.out.println(url.getPath()); // /helloworld/index.jsp
            // 全路径
            System.out.println(url.getFile()); // /helloworld/index.jsp?username=ymb&pwd=123
            // 参数
            System.out.println(url.getQuery()); // username=ymb&pwd=123
        } catch (MalformedURLException e) {
            e.printStackTrace();
        }
    }
}
